package TrueTopic;

import java.util.Scanner;

public class Test_2020_F {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-->0) {
            int n = sc.nextInt();
            for(int i=n+1;;i++){
                String str = i+"";
                if(!(str.contains("7") || i%7==0)){
                    System.out.println(i);
                    break;
                }
            }
        }
    }
}
